﻿<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:Microsoft.ALMRangers.BranchTool.VSExtension.ViewModels"
        xmlns:PlatformUI="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.11.0" 
        x:Class="Microsoft.ALMRangers.BranchTool.VSExtension.Views.SelectBranchPlan"
        Title="Select Branch Plan" Height="375" Width="630" ShowInTaskbar="False">
    <Window.Resources>
        <PlatformUI:BooleanToHiddenVisibilityConverter x:Key="BooleanToHiddenVisibilityConverter"/>

        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

        <DataTemplate x:Key="ArgumentValue">
            <StackPanel Orientation="Vertical">
                <Label Content="{Binding Value}"  Width="Auto" >
                    <Label.Style >
                        <Style TargetType="{x:Type Label}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsHandeledByExtension}" Value="true">
                                    <Setter Property="Visibility" Value="Visible" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding IsHandeledByExtension}" Value="false">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                </DataTrigger>

                            </Style.Triggers>
                        </Style>

                    </Label.Style>
                </Label>

                <TextBox Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  >
                    <TextBox.Style >
                        <Style TargetType="{x:Type TextBox}">
                            <Setter Property="Visibility" Value="Collapsed" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Optional}" Value="false">
                                    <Setter Property="Background" Value="Khaki" />                                    
                                </DataTrigger>                           
                                <DataTrigger Binding="{Binding TypeInformation}" Value="string">
                                    <Setter Property="Visibility" Value="Visible" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding TypeInformation}" Value="">
                                    <Setter Property="Visibility" Value="Visible" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding IsHandeledByExtension}" Value="true">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>

                    </TextBox.Style>

                </TextBox>
                <CheckBox IsChecked="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  >
                    <CheckBox.Style >
                        <Style TargetType="{x:Type CheckBox}">
                            <Setter Property="Visibility" Value="Collapsed" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsHandeledByExtension}" Value="true">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding TypeInformation}" Value="bool">
                                    <Setter Property="Visibility" Value="Visible" />
                                </DataTrigger>


                            </Style.Triggers>
                        </Style>
                    </CheckBox.Style>
                </CheckBox>

            </StackPanel>
        </DataTemplate>

        <Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}">

            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="{x:Null}" />
                    <Setter Property="BorderBrush" Value="{x:Null}" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="NoHitTest" TargetType="{x:Type DataGridCell}">
            <Setter Property="IsHitTestVisible" Value="False"/>
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>


        <Style TargetType="{x:Type DataGrid}" >
            <Setter Property="GridLinesVisibility" Value="None" />
            <Setter Property="BorderThickness" Value="0" />
        </Style>
        <Style TargetType="{x:Type DataGridColumnHeader}" >
            <Setter Property="Background" Value="White" />
            <Setter Property="BorderBrush" Value="White" />
            <Setter Property="BorderThickness" Value="0" />

        </Style>
        <Style TargetType="{x:Type DataGridRow}" />

    </Window.Resources>
    <Window.DataContext >
        <vm:SelectBranchPlanViewModel />
    </Window.DataContext>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Name="grpProgress" Visibility="{Binding ShowProgress, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
            <Grid.RowDefinitions>
                <RowDefinition Height="30px" />
                <RowDefinition Height="*" />
                <RowDefinition Height="30px" />
            </Grid.RowDefinitions>
            <ProgressBar Grid.Row="0" Height="16"  x:Name="barProgress" Margin="12,12,12,0" VerticalAlignment="Top" Value="{Binding JobProgress}"   />
            <Label Grid.Row="0"   Padding="0" Margin="12,12,12,0" x:Name="lblProgress" VerticalAlignment="Top" FontSize="10" Opacity="1" HorizontalContentAlignment="Center" Content="{Binding JobCurrentOperation}" />
            <ScrollViewer Grid.Row="1"  VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="12,10,12,0 " VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                <TextBlock  x:Name="txtLog"  Text="{Binding JobOperationLog}" />
            </ScrollViewer>
            <Button Grid.Row="2"  x:Name="cmdClose" Width="100px" Content="Close" HorizontalAlignment="Center"  VerticalAlignment="Bottom" Margin="0,0,0,4" Click="CmdClose_Click" Visibility="{Binding ShowProgress, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" IsEnabled="{Binding IsJobDone, Mode=OneWay}"/>
        </Grid>
        
            <Grid x:Name="grdForm"  Visibility="{Binding ShowForm, Converter={StaticResource BooleanToVisibilityConverter}}"  VerticalAlignment="Stretch" >
            <Grid.ColumnDefinitions>

                <ColumnDefinition Width="207*"/>
                <ColumnDefinition Width="124*"/>
                <ColumnDefinition Width="291*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="0px" />
                <RowDefinition Height="2*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="30px" />
            </Grid.RowDefinitions>



            <ListBox Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" x:Name="listBox" Margin="10,10,5,5" VerticalAlignment="Stretch" ItemsSource="{Binding BranchPlans}" DisplayMemberPath="Name"  SelectedValuePath="Uri" SelectedItem="{Binding SelectedBranchPlan, Mode=TwoWay}" SelectionChanged="ListBox_SelectionChanged"  />
            <WebBrowser x:Name="Browser" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch"  Margin="5,10,10,10" VerticalAlignment="Stretch"   OpacityMask="Black" Grid.ColumnSpan="2"/>
            <ItemsControl Visibility="Collapsed" Grid.Column="1"  Grid.Row="2" Grid.ColumnSpan="2" ItemsSource="{Binding Arguments, Mode=TwoWay}" HorizontalAlignment="Stretch" Margin="5,5,10,5" VerticalAlignment="Stretch"  ItemTemplate="{StaticResource ArgumentValue}"/>



            <DataGrid Visibility="Visible" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Stretch" Margin="5,7,10,3" VerticalAlignment="Stretch" ItemsSource="{Binding Arguments, Mode=TwoWay}" AutoGenerateColumns="False" Grid.ColumnSpan="2" SelectionUnit="Cell" SelectionMode="Single" RowStyleSelector="{x:Null}" RowHeaderWidth="0" >
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding Name}" ClipboardContentBinding="{x:Null}" Header="Argument" IsReadOnly="True" CellStyle="{StaticResource NoHitTest}"  />
                    <DataGridTemplateColumn  Header="Value" Width="*" CellTemplate="{StaticResource ArgumentValue}"/>
                </DataGrid.Columns>
            </DataGrid>

            <StackPanel Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" Height="30" Margin="15,0,5,0" VerticalAlignment="Bottom" Width="602" Orientation="Horizontal"  >
                <Button Content="Apply" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="75" Click="CmdApply_Click"   x:Name="cmdApply"/>
                <Button Content="Cancel" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="75" Click="CmdClose_Click"  x:Name="cmdCancel" />


            </StackPanel>

        </Grid>
    
    </Grid>
</Window>
